layui.use(['form','layer','table'],function(){
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery,
        table = layui.table;

    //文章列表
    var tableIns = table.render({
        elem: '#toolList',
        url : 'list',
        cellMinWidth : 95,
        page : true,
        height : "full-125",
        limit : 5,
        limits : [10,15,20,25],
        id : "toolListTable",
        cols : [[
            {field: 'id', title: 'ID', width:60, align:"center"},
            {field: 'toolName', title: '分类名称', width:250},
            {field: 'url', title: '链接地址', align:'left', templet:function(d){
                    return '<a href="'+d.url+'" target="_blank">'+d.url+'</a>'
                }},
            {field: 'addDate', title: '添加日期', align:'center'},
            {title: '操作', width:250, templet:'#toolListBar',fixed:"right",align:"center"}
        ]]
    });



    //添加文章
    function addTool(){
        var index = layui.layer.open({
            title : "添加工具",
            type : 2,
            shadeClose: false,           //弹出框之外的地方是否可以点击
            area : ["400px","250px"],
            content : "toolAdd",
            success : function(layero, index){
                var body = layui.layer.getChildFrame('body', index);
            }
        })
    }



    $(".addTool_btn").click(function(){
        addTool();
    })

    //列表操作
    table.on('tool(toolList)', function(obj){
        var layEvent = obj.event,
            data = obj.data;

        if(layEvent === 'del'){
            //删除
            layer.confirm('确定删除此工具？',{icon:3, title:'提示信息'},function(index){
                $.post("delete",{
                    id : data.id  //将需要删除的newsId作为参数传入
                },function(data){
                    data = JSON.parse(data)
                    if(data.flag ==="success"){
                        layer.msg("删除成功");
                        tableIns.reload();
                        layer.close(index);
                    }else if(data.flag === "permissions"){
                        layer.msg("权限不足，无法删除！",{icon: 5});
                    }else{
                        layer.msg("删除失败！", {icon: 2});
                    }
                })
            });

        }
    });

})